//
//  DepositViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15/9/24.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "DepositViewController.h"
#import "HZAreaPickerView.h"
#import "UIImageView+WebCache.h"
#import "EGORefreshTableHeaderView.h"
#import "SearchMemberTableViewCell.h"
#import "FPNumberPadView.h"
#import "DepositTableViewCell.h"
#import "GuideListTableViewCell.h"

#import "OldMeterialTableViewCell.h"
#import "CaptureViewController.h"
#import "PassImageDelegate.h"
#import "UpYun.h"
#import "OrderDetailViewController.h"

#import "CancelOrderOrDepositViewController.h"
#import "CashierViewController.h"
#import "DepositDetailViewController.h"

#import "AddNewDepositViewController.h"
#import "CashierViewController.h"
#import "FilterViewController.h"
#import "AddMemberViewController.h"
//#import "FPNumberPadSingleton.h"

@interface DepositViewController ()<HZAreaPickerDelegate,EGORefreshTableHeaderDelegate,FPNumberPadViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,PassImageDelegate,OrderDetailDelegate,CancelOrderOrDepositDelegate,DepositTableViewCellDelegate,CashierViewControllerDelegate,DepositDetailDelegate,AddNewDepositDelegate,FilterViewControllerDelegate,AddMemberDelegate>
{
    AddMemberViewController *addMemberVC;
    FilterViewController *filterVC;
    NSMutableArray *depositNumArray;
    EGORefreshTableHeaderView *_refreshHeaderView;
    BOOL _reloading;
    
    OrderDetailViewController *orderDetailVC;
    CancelOrderOrDepositViewController *cancelOrderVC;
    CashierViewController *cashierVC;
    DepositDetailViewController *depositDetailVC;
    
     AddNewDepositViewController *addNewDepositVC;
    
    NSUInteger _memberPageIndex;
    NSUInteger _memberTotalCount;
    NSUInteger _memberTotalPage;
    
    NSMutableArray *memberCodeArray;
    NSMutableArray *memberNameArray;
    NSMutableArray *memberPhoneArray;
    NSMutableArray *memberGradeArray;
    NSMutableArray *memberAddressArray;
    NSMutableArray *memberIntegralArray;
    NSMutableArray *memberIntegralAmountArray;
    NSMutableArray *memberSexArray;
    
     NSInteger imageBtnTag;
    
    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;
    // NSUInteger _totalOrder;
    
    NSMutableArray *orderNumArray;
    NSMutableArray *orderDocTypeArray;
    NSMutableArray *orderTotalNumberArray;
    NSMutableArray *orderStatusArray;
    NSMutableArray *orderStatus1Array;
    NSMutableArray *orderWeightArray;
    NSMutableArray *orderShipmentStatusArray;
    NSMutableArray *productNameArray;
    NSMutableArray *guideNameArray;
    NSMutableArray *memberNameListArray;
    NSMutableArray *priceArray;
    NSMutableArray *dateArray;
    
    // NSMutableArray *mGuidesArray;
    NSMutableArray *cashierGuideNameArray;
    NSMutableArray *cashierGuideCodeArray;
    NSString *guideCodeStr;
    NSString *memberCodeStr;
    BOOL isOpened;
    
    NSMutableArray *upYunImageArray;
    
    
    NSUInteger orderListCellTag;
    
    
    BOOL addMemberisOpened;
    NSMutableArray *mFeaturesArray;
    NSMutableArray *featureCodeArray;
    NSMutableArray *featureNameArray;
    NSMutableArray *selectFeatureCodeArray;
    
    //  NSMutableArray *mGuidesArray;
    NSMutableArray *addMemberGuideNameArray;
    NSMutableArray *addMemberGuideCodeArray;
    NSString *provinceStr;
    NSString *cityStr;
    NSString *regionStr;
    NSString *addressStr;
    NSString *sexStr;
    NSString *qrCodeStr;
    
    NSString *addMemberGuideCodeStr;
    NSString *addMemberMemberCodeStr;
    
    NSMutableArray *orderDetailProductNameArray;
    NSMutableArray *orderDetailProductCodeArray;
    NSMutableArray *orderDetailProductPriceArray;
    NSMutableArray *orderDetailProductUrlArray;
    NSMutableArray *orderDetailWeightArray;
    NSMutableArray *orderDetailProductAddressArray;
    NSMutableArray *orderDetailAttributeArray;
    
    float cashierAmountFloat;
    float balanceAmountFloat;
    float oldMeterialTotalAmountFloat;
    NSInteger buShouYinCellTag;
    
    NSString *openIdStr;
    NSString *orderStr;
    
    
    NSString *buShouYinOrBuDengStr;
    
    NSInteger cellTag;
    
    
    float depositPrice;
    
    UITextField *inputTextField;
    
    
    NSString *integralAvailabalStr;
    
    BOOL popIsOpen;
    NSInteger popTag;
    
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

    

}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@property (strong, nonatomic) NSString *areaValue, *cityValue;
@property (strong, nonatomic) HZAreaPickerView *locatePicker;

@end

@implementation DepositViewController
@synthesize areaValue=_areaValue, cityValue=_cityValue;
@synthesize locatePicker=_locatePicker;
-(void)viewWillAppear:(BOOL)animated
{
   if ([_isLoad isEqualToString:@"N"]) {
        if (orderDetailVC.view!=nil) {
            [orderDetailVC.view removeFromSuperview];
            [orderDetailVC removeFromParentViewController];
            
        }
        if (addMemberVC.view!=nil) {
            if (addMemberVC.timer!=nil) {
                [addMemberVC.timer invalidate];
                addMemberVC.timer=nil;
            }
            
            [addMemberVC removeFromParentViewController];
            [addMemberVC.view removeFromSuperview];
            
        }

        if (cancelOrderVC.view!=nil) {
            [cancelOrderVC.view removeFromSuperview];
            [cancelOrderVC removeFromParentViewController];
            
        }
        if (cashierVC.view!=nil) {
            [cashierVC.view removeFromSuperview];
            [cashierVC removeFromParentViewController];
            
        }
        if (depositDetailVC.view!=nil) {
            [depositDetailVC.view removeFromSuperview];
            [depositDetailVC removeFromParentViewController];
            
        }
        if (filterVC.view!=nil) {
            
            [filterVC removeFromParentViewController];
            [filterVC.view removeFromSuperview];
            
        }

    [_addDepositButton addTarget:self action:@selector(addDepositButtonClick) forControlEvents:UIControlEventTouchUpInside];

    [self initOrderList];
   
    [self initSearMemberView];
    [self initOrderFilterView];
   
    [self initAddDeposit];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];
    }

}
-(void)initAddDeposit
{
    FPNumberPadView *numberPadView1 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
    // numberPadView.FPNumberPaddelegate=self;
    numberPadView1.textField = _depositAmountTextField;
    FPNumberPadView *numberPadView2 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
    // numberPadView.FPNumberPaddelegate=self;
    numberPadView2.textField = _minAmountTextField;
    FPNumberPadView *numberPadView3 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
    // numberPadView.FPNumberPaddelegate=self;
    numberPadView3.textField = _maxAmountTextField;
   
    memberCodeStr=@"";
     imageBtnTag=10000;
    cashierGuideNameArray=[NSMutableArray array];
    cashierGuideCodeArray=[NSMutableArray array];
     upYunImageArray=[NSMutableArray array];
    CGRect frame=_addDepositView.frame;
    frame.origin.y=768;
    [_addDepositView setFrame:frame];
    
    popIsOpen=NO;
    CGRect frame1=_popScrollView.frame;
    frame1.size.height=1;
    [_popScrollView setFrame:frame1];
    
    _popScrollView.hidden=YES;

    
    CGRect viewFrame4=_photoPickerViewContainer.frame;
    viewFrame4.origin.y=768;
    _photoPickerViewContainer.frame=viewFrame4;
    
    CGRect frame0=_addPictureButton.frame;
    frame0.origin.x=16;
    frame0.origin.y=10;
    _addPictureButton.frame=frame0;
    for (UIView *v in _pictureView.subviews) {
        if (v.tag!=90) {
            
            [v removeFromSuperview];
        }
        
    }

    [_addMemberBtn addTarget:self action:@selector(addMemberBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    CGRect viewFrame1=_remarkViewContainer.frame;
    viewFrame1.origin.y=_pictureView.frame.origin.y+_pictureView.frame.size.height+15;
    _remarkViewContainer.frame=viewFrame1;
     [_addDepositScrollView setContentSize:CGSizeMake(0, _remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height)];
    [_addDepositScrollView setShowsVerticalScrollIndicator:NO];
    [_addDepositScrollView setScrollEnabled:YES];
    
    _addDepositRemarkView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _addDepositRemarkView.layer.borderWidth= 1.0f;
    _addDepositRemarkView.layer.cornerRadius=3;
    

    [_addDepositAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_addDepositAlphaView addTarget:self action:@selector(addDepositAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    [_guideListBtn addTarget:self action:@selector(selectGuideBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_chengseListBtn addTarget:self action:@selector(chengSeListBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_zhushiListBtn addTarget:self action:@selector(chengSeListBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_shipinListBtn addTarget:self action:@selector(chengSeListBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
//orderDetailDelegate
-(void)orderDetailAlphaViewClick
{
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
}
-(void)RelateDepositBtnClick
{
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    depositDetailVC=[[DepositDetailViewController alloc] init];
    depositDetailVC.delegate=self;
    depositDetailVC.docNumStr=orderDetailVC.relatedDocNumLabel.text;
    
    
    depositDetailVC.view.frame = CGRectMake(0,
                                            0,
                                            self.view.bounds.size.width,
                                            self.view.bounds.size.height);
    
    [self addChildViewController:depositDetailVC];
    [self.view addSubview:depositDetailVC.view];
    
}
-(void)CancelOrderBtnClick
{
    //    if (orderDetailVC.view!=nil) {
    //      //  NSLog(@"rrwrwrwrwrw");
    //        [orderDetailVC removeFromParentViewController];
    //        [orderDetailVC.view removeFromSuperview];
    //
    //    }
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    cancelOrderVC=[[CancelOrderOrDepositViewController alloc] init];
    cancelOrderVC.delegate=self;
    cancelOrderVC.DocNumStr=orderDetailVC.detailNumLabel.text;
    cancelOrderVC.DocTypeStr=@"Order";
    cancelOrderVC.titleStr=@"取消订单";
    
    cancelOrderVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOrderVC];
    [self.view addSubview:cancelOrderVC.view];
    // [self.view bringSubviewToFront:cancelOrderVC.view];
    
}

//cancelOrderOrDepositDelegate
-(void)confirmCancelOrderOrDepositBtnClick
{
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
    if (cancelOrderVC.view!=nil) {
        [cancelOrderVC.view removeFromSuperview];
        [cancelOrderVC removeFromParentViewController];
        
    }
    if (cashierVC.view!=nil) {
        [cashierVC.view removeFromSuperview];
        [cashierVC removeFromParentViewController];
        
    }
    if (depositDetailVC.view!=nil) {
        [depositDetailVC.view removeFromSuperview];
        [depositDetailVC removeFromParentViewController];
        
    }
    
    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderDocTypeArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];
    
}
-(void)buShouYinBtnClick:(NSUInteger)tag
{
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    cashierVC=[[CashierViewController alloc] init];
    cashierVC.delegate=self;
    cashierVC.docTypeStr=@"Deposit";
    cashierVC.docNumStr=[orderNumArray objectAtIndex:tag];
    cashierVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cashierVC];
    [self.view addSubview:cashierVC.view];
    //[self.view bringSubviewToFront:cashierVC.view];
}
//cashierViewcontrollerDelegate
-(void)CashierAlphaViewClick
{
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }

}
-(void)CashierSuccess
{
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderDocTypeArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];


}
-(IBAction)addPictureBtnClick:(id)sender
{
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_photoPickerViewContainer.frame;
         viewFrame.origin.y=0;
         _photoPickerViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
         
     }];
    
}

-(void)addDepositButtonClick
{
    guideCodeStr=[Global getGuideCodeStr];
    _guideNameLabel.text=[Global getGuideNameStr];
    
    [Global resizeForLable:_guideNameLabel WithText:_guideNameLabel.text parentView:self.view];
    CGRect frameK=_guideNameLabel.frame;
    frameK.origin.x=_guideListArrowImage.frame.origin.x-frameK.size.width-5;
    _guideNameLabel.frame=frameK;
    
    [cashierGuideCodeArray removeAllObjects];
    [cashierGuideNameArray removeAllObjects];
    [_guideListTableView reloadData];
    _guideListViewContainer.hidden=YES;
    CGRect frame=_guideListViewContainer.frame;
    frame.size.height=1;
    [_guideListViewContainer setFrame:frame];
   
    isOpened=NO;
    
    _memberInfoNoteLabel.hidden=NO;
    memberCodeStr=@"";
    _totalAmountLabel.text=@"";
    _depositAmountTextField.text=@"";
    _minAmountTextField.text=@"";
    _maxAmountTextField.text=@"";
    _chengseTextField.text=@"";
    _shiPinTextField.text=@"";
    _zhuShiTextField.text=@"";
    _addDepositRemarkView.text=@"";
    _chengseListBtn.titleLabel.text=@"";
    _zhushiListBtn.titleLabel.text=@"";
    _shipinListBtn.titleLabel.text=@"";
    _addDepositRemarkViewImage.hidden=NO;
    _addDepositRemarkViewLabel.hidden=NO;
    
    for (UIView *v in _pictureView.subviews) {
        if (v.tag!=90) {
            
            [v removeFromSuperview];
        }
        
    }

    CGRect viewFrame11=_addPictureButton.frame;
    viewFrame11.origin.y=10;
    viewFrame11.origin.x=16;
    _addPictureButton.frame=viewFrame11;
    
    CGRect viewFrame0=_pictureViewLineLabel.frame;
    viewFrame0.origin.y= _pictureView.frame.size.height-1;
    _pictureViewLineLabel.frame=viewFrame0;
    [UIView animateWithDuration:0.5 animations:^{
        
        CGRect frame=_addDepositView.frame;
        frame.origin.y=0;
        [_addDepositView setFrame:frame];
    } completion:^(BOOL finished){
        
    }];

}
-(void)addDepositAlphaViewClick
{
    [_minAmountTextField resignFirstResponder];
    [_maxAmountTextField resignFirstResponder];
    [_depositAmountTextField resignFirstResponder];
    
    
    [_addDepositScrollView setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.5 animations:^{
        
        CGRect frame=_addDepositView.frame;
        frame.origin.y=768;
        [_addDepositView setFrame:frame];
    } completion:^(BOOL finished){
       
    }];

}
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)initSearMemberView
{
    memberCodeArray=[NSMutableArray array];
    memberNameArray=[NSMutableArray array];
    memberPhoneArray=[NSMutableArray array];
    memberGradeArray=[NSMutableArray array];
    memberAddressArray=[NSMutableArray array];
    memberIntegralArray=[NSMutableArray array];
    memberSexArray=[NSMutableArray array];
    memberIntegralAmountArray=[NSMutableArray array];
    
    openIdStr=@"";
    
    [_searchMemberAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_searchMemberAlphaView addTarget:self action:@selector(searchMemberAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    CGRect frame1=_searchMemberViewContainer.frame;
    frame1.origin.y=768;
    [_searchMemberViewContainer setFrame:frame1];
}
-(void)searchMemberAlphaViewClick
{
    [_searchMemberTextField resignFirstResponder];
    
    [_searchTextField resignFirstResponder];
    
    CGRect frame1=_searchMemberViewContainer.frame;
    frame1.origin.y=768;
    [_searchMemberViewContainer setFrame:frame1];
    
}
-(void)chengSeListBtnClick:(UIButton *)sender
{
    [_minAmountTextField resignFirstResponder];
    [_maxAmountTextField resignFirstResponder];
    [_depositAmountTextField resignFirstResponder];
    [_addDepositScrollView bringSubviewToFront:_popScrollView];
   
    if (popIsOpen) {
        _popScrollView.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            CGRect frame=_popScrollView.frame;
            
            frame.size.height=1;
            [_popScrollView setFrame:frame];
            
        } completion:^(BOOL finished){
            popIsOpen=NO;
        }];
        
    }
    else
    {
        
        for (UIView *v in _popScrollView.subviews) {
            
            [v removeFromSuperview];
        }

        _popScrollView.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
            
            CGRect frame=_popScrollView.frame;
            if (sender.tag==1000) {
                [self requestChengSe];
                frame.origin.y=402;
                 frame.size.height=366;
            }
            else if(sender.tag==1001)
            {
                [self requestZhuShi];
                 frame.origin.y=458;
                frame.size.height=310;
            }
            else if(sender.tag==1002)
            {
                 [self requestShiPin];
                frame.origin.y=512;
                frame.size.height=276;
            }

            
            [_popScrollView setFrame:frame];
            
        } completion:^(BOOL finished){
            popIsOpen=YES;
        }];
        
    }
    
}
-(void)requestChengSe
{
    
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        
        [HttpRequest requestData:@"Guide/FinenessList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            // [_cashierSearchMemberTextField resignFirstResponder];
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    if ([severDataDict.dataDict objectForKey:@"ResultString"]!= [NSNull null] )
                    {
//                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
//                        //  [Global showTextHud:requestResultStr view:self.view];
//                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        NSMutableArray *dataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                        NSMutableArray *nameArray=[NSMutableArray array];
                        NSMutableArray *codeArray=[NSMutableArray array];
                        for (int i=0; i<dataLineArray.count; i++) {
                            [codeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FinenessCode"]];
                            [nameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FinenessName"]];
                        }
                        for (UIView *v in _popScrollView.subviews) {
                                
                                [v removeFromSuperview];
                        }
                        _popScrollView.hidden=NO;
                        popIsOpen=YES;
                        
                        for (int i=0; i<nameArray.count; i++) {
                            
                            UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
                            CGRect rect=button.frame;
                            rect.size.height=50;
                            rect.size.width=545;
                            rect.origin.x=10;
                            rect.origin.y=50*i;
                            button.frame=rect;
                            button.tag=100+i;
                            [button setBackgroundColor:[UIColor clearColor]];
                            [button setTitle:[nameArray objectAtIndex:i] forState:UIControlStateNormal];
                            
                            [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                            [button addTarget:self action:@selector(selectNameBtn:) forControlEvents:UIControlEventTouchUpInside];
                            
                            
                            UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(25, 20,400, 20)];
                            [textLabel setText:[nameArray objectAtIndex:i]];
                            [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
                            [textLabel setBackgroundColor:[UIColor clearColor]];
                            [button addSubview:textLabel];
                            
                            UILabel *codeLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0,1,1)];
                            codeLabel.text=[codeArray objectAtIndex:i];
                            codeLabel.tag=5000;
                            codeLabel.hidden=YES;
                            [button addSubview:codeLabel];
                            
                            UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(5,49, 590, 1)];
                            // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
                            [lineLabel setBackgroundColor:[UIColor clearColor]];
                            [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
                            [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
                            
                            [button addSubview:lineLabel];
                            [_popScrollView addSubview:button];
                            
                            NSInteger index= [nameArray indexOfObject:_chengseTextField.text];
                             if (index!=NSNotFound) {
                            popTag=index;
                            

                            if (i==popTag) {
                                
                                UIImageView *selectImageview=[[UIImageView alloc] initWithFrame:CGRectMake(540, 11, 30, 30)];
                                [selectImageview setImage:[UIImage imageNamed:@"xuanzhong_.png"]];
                                [button addSubview:selectImageview];
                            }
                             }
                            
                            
                        }
                        

                        [_popScrollView setContentSize:CGSizeMake(0, 50*nameArray.count)];
                        [_popScrollView setShowsVerticalScrollIndicator:NO];
                        [_popScrollView setScrollEnabled:YES];
                    }
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                        //    [Global loginViewController:self];
                    }
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
    }
}

-(void)requestShiPin
{
    
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        
        [HttpRequest requestData:@"Guide/GetMIThrtypeList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            // [_cashierSearchMemberTextField resignFirstResponder];
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    if ([severDataDict.dataDict objectForKey:@"ResultString"]!= [NSNull null] )
                    {
//                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
//                        //  [Global showTextHud:requestResultStr view:self.view];
//                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        NSMutableArray *dataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                        NSMutableArray *nameArray=[NSMutableArray array];
                        NSMutableArray *codeArray=[NSMutableArray array];
                        for (int i=0; i<dataLineArray.count; i++) {
                            [codeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"IThrtypeCode"]];
                            [nameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"IThrtypeName"]];
                        }
                        for (UIView *v in _popScrollView.subviews) {
                            
                            [v removeFromSuperview];
                        }
                        _popScrollView.hidden=NO;
                        popIsOpen=YES;
                        
                        for (int i=0; i<nameArray.count; i++) {
                            
                            UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
                            CGRect rect=button.frame;
                            rect.size.height=50;
                            rect.size.width=545;
                            rect.origin.x=20;
                            rect.origin.y=50*i;
                            button.frame=rect;
                            button.tag=400+i;
                            [button setBackgroundColor:[UIColor clearColor]];
                            [button setTitle:[nameArray objectAtIndex:i] forState:UIControlStateNormal];
                            
                            [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                            [button addTarget:self action:@selector(selectNameBtn:) forControlEvents:UIControlEventTouchUpInside];
                            
                            
                            UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(25, 20,400, 20)];
                            [textLabel setText:[nameArray objectAtIndex:i]];
                            [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
                            [textLabel setBackgroundColor:[UIColor clearColor]];
                            [button addSubview:textLabel];
                            
                            UILabel *codeLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0,1,1)];
                            codeLabel.text=[codeArray objectAtIndex:i];
                            codeLabel.tag=5000;
                            codeLabel.hidden=YES;
                            [button addSubview:codeLabel];
                            
                            UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,49, 590, 1)];
                            // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
                            [lineLabel setBackgroundColor:[UIColor clearColor]];
                            [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
                            [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
                            
                            [button addSubview:lineLabel];
                            [_popScrollView addSubview:button];
                            
                            NSInteger index= [nameArray indexOfObject:_shiPinTextField.text];
                            if (index!=NSNotFound) {
                                popTag=index;
                                
                                
                                if (i==popTag) {
                                    
                                    UIImageView *selectImageview=[[UIImageView alloc] initWithFrame:CGRectMake(530, 11, 30, 30)];
                                    [selectImageview setImage:[UIImage imageNamed:@"xuanzhong_.png"]];
                                    [button addSubview:selectImageview];
                                }
                            }
                            
                            
                        }
                        
                        
                        [_popScrollView setContentSize:CGSizeMake(0, 50*nameArray.count)];
                        [_popScrollView setShowsVerticalScrollIndicator:NO];
                        [_popScrollView setScrollEnabled:YES];
                    }
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                        //    [Global loginViewController:self];
                    }
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
    }
}
-(void)requestZhuShi
{
    
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:@"ProductName2" forKey:@"KeyWord"];
        
        [HttpRequest requestData:@"Common/GetDictList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            // [_cashierSearchMemberTextField resignFirstResponder];
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    if ([severDataDict.dataDict objectForKey:@"ResultString"]!= [NSNull null] )
                    {
//                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
//                        //  [Global showTextHud:requestResultStr view:self.view];
//                       
//                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        NSMutableArray *dataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                        NSMutableArray *nameArray=[NSMutableArray array];
                        NSMutableArray *codeArray=[NSMutableArray array];
                        for (int i=0; i<dataLineArray.count; i++) {
                            [codeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"Code"]];
                            [nameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"Name"]];
                        }
                        for (UIView *v in _popScrollView.subviews) {
                            
                            [v removeFromSuperview];
                        }
                        _popScrollView.hidden=NO;
                        popIsOpen=YES;
                        
                        for (int i=0; i<nameArray.count; i++) {
                            
                            UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
                            CGRect rect=button.frame;
                            rect.size.height=50;
                            rect.size.width=545;
                            rect.origin.x=20;
                            rect.origin.y=50*i;
                            button.frame=rect;
                            button.tag=800+i;
                            [button setBackgroundColor:[UIColor clearColor]];
                            [button setTitle:[nameArray objectAtIndex:i] forState:UIControlStateNormal];
                            
                            [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                            [button addTarget:self action:@selector(selectNameBtn:) forControlEvents:UIControlEventTouchUpInside];
                            
                            UILabel *codeLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0,1,1)];
                            codeLabel.text=[codeArray objectAtIndex:i];
                            codeLabel.tag=5000;
                            codeLabel.hidden=YES;
                            [button addSubview:codeLabel];
                            
                            UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(25, 20,400, 20)];
                            [textLabel setText:[nameArray objectAtIndex:i]];
                            [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
                            [textLabel setBackgroundColor:[UIColor clearColor]];
                            [button addSubview:textLabel];
                            
                            
                            
                            UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,49, 590, 1)];
                            // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
                            [lineLabel setBackgroundColor:[UIColor clearColor]];
                            [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
                            [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
                            
                            [button addSubview:lineLabel];
                            [_popScrollView addSubview:button];
                            
                            NSInteger index= [nameArray indexOfObject:_zhuShiTextField.text];
                            if (index!=NSNotFound) {
                                popTag=index;
                                
                                
                                if (i==popTag) {
                                    
                                    UIImageView *selectImageview=[[UIImageView alloc] initWithFrame:CGRectMake(530, 11, 30, 30)];
                                    [selectImageview setImage:[UIImage imageNamed:@"xuanzhong_.png"]];
                                    [button addSubview:selectImageview];
                                }
                            }
                            
                            
                        }
                        
                        
                        [_popScrollView setContentSize:CGSizeMake(0, 50*nameArray.count)];
                        [_popScrollView setShowsVerticalScrollIndicator:NO];
                        [_popScrollView setScrollEnabled:YES];
                    }
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                        //    [Global loginViewController:self];
                    }
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
    }
}


-(void)selectNameBtn:(UIButton *)sender
{
    if (sender.tag<399) {
    UIImageView *selectImageview=[[UIImageView alloc] initWithFrame:CGRectMake(540, 11, 30, 30)];
    [selectImageview setImage:[UIImage imageNamed:@"xuanzhong_.png"]];
    [sender addSubview:selectImageview];
    popTag=sender.tag-100;
    _chengseTextField.text=sender.titleLabel.text;
    UILabel *codeLabel=(UILabel *)[sender  viewWithTag:5000] ;
        
    [_chengseListBtn setTitle:codeLabel.text forState:UIControlStateNormal];
    [_chengseListBtn setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
   
    }
    else if (sender.tag<799&&sender.tag>399)
    {
        UIImageView *selectImageview=[[UIImageView alloc] initWithFrame:CGRectMake(530, 11, 30, 30)];
        [selectImageview setImage:[UIImage imageNamed:@"xuanzhong_.png"]];
        [sender addSubview:selectImageview];
        popTag=sender.tag-400;
        _shiPinTextField.text=sender.titleLabel.text;
        UILabel *codeLabel=(UILabel *)[sender  viewWithTag:5000] ;
        
        [_shipinListBtn setTitle:codeLabel.text forState:UIControlStateNormal];
        [_shipinListBtn setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];

    }
    else if (sender.tag>799)
    {
        UIImageView *selectImageview=[[UIImageView alloc] initWithFrame:CGRectMake(530, 11, 30, 30)];
        [selectImageview setImage:[UIImage imageNamed:@"xuanzhong_.png"]];
        [sender addSubview:selectImageview];
        
        popTag=sender.tag-800;
         _zhuShiTextField.text=sender.titleLabel.text;
        UILabel *codeLabel=(UILabel *)[sender  viewWithTag:5000] ;
        
        [_zhushiListBtn setTitle:codeLabel.text forState:UIControlStateNormal];
        [_zhushiListBtn setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    }
    
    [UIView animateWithDuration:0.1f animations:^
     {
         CGRect frame1=_popScrollView.frame;
         frame1.size.height=1;
         [_popScrollView setFrame:frame1];
     }completion:^(BOOL finished) {
         _popScrollView.hidden=YES;
         popIsOpen=NO;
         
     }];
}

-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"Deposit";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];
}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderDocTypeArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];

    
}

-(void) loadOrderNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _TotalCount<=orderNumArray.count)
        return;
    if(oldPageNum == 0){
        [orderNumArray removeAllObjects];
        [_depositListTabelView reloadData];
    }
    _PageIndex=oldPageNum+1;
    [self requestDepositList: _PageIndex pageSize:7];
}
-(void)requestDepositList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
       // NSLog(@"_searchTextField.text===%@",_searchTextField.text);
        [params setObject:_searchTextField.text forKey:@"KeyWord"];
        
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }
        
        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
      //   NSLog(@"paramsLIST11111====%@",params);
        [HttpRequest requestData:@"Guide/DepositList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    //   NSLog(@"333==%@",severDataDict.dataDict);
                    _TotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                  /////  NSInteger numberInteger=[[severDataDict.dataDict objectForKey:@"DocQCount"] integerValue];
                //float gramInteger=[[severDataDict.dataDict objectForKey:@"DocGramTotal"] floatValue];
                    float priceInteger=[[severDataDict.dataDict objectForKey:@"DocPriceTotal"] floatValue];
                    _totalOrderLabel.text=[NSString stringWithFormat:@"共有%lu条记录  ¥%@",(unsigned long)_TotalCount,[Global floatConvertPercentile:priceInteger]];
                    if (_TotalCount%7!=0) {
                        _TotalPage=_TotalCount/7+1;
                    }
                    else if (_TotalCount%7==0)
                    {
                        _TotalPage=_TotalCount/7;
                    }
                    
                    NSMutableArray *mOrderArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    
                    //     NSLog(@"mOrderArray===%@",mOrderArray);
                    if ( mOrderArray.count>0) {
                        for (int i=0; i< mOrderArray.count; i++) {
                            
                            [orderNumArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [orderTotalNumberArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"Number"]];
                            [orderStatusArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [orderDocTypeArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocType"]];
                            
                           // [orderWeightArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                          //  [orderShipmentStatusArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocType"]];
                           // [productNameArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [guideNameArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [memberNameListArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"MemberName"]];
                            [priceArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"Subscription"]];
                            [dateArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocDate"]];
                        }
                    }
                    [_depositListTabelView reloadData];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                        // [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}


-(void) loadMemberNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _memberTotalCount<=memberCodeArray.count)
        return;
    if(oldPageNum == 0){
        [memberCodeArray removeAllObjects];
        [_searchMemberTableView reloadData];
    }
    _memberPageIndex=oldPageNum+1;
    [self requestMemberList: _memberPageIndex pageSize:8];
}
-(void)requestMemberList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchMemberTextField.text forKey:@"KeyWord"];
        //   NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"Guide/MemberList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    //  NSLog(@"tttt11====%@",severDataDict.dataDict);
                    _memberTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _totalMemberLabel.text=[NSString stringWithFormat:@"共有%lu个结果",(unsigned long)_memberTotalCount];
                    if (_memberTotalCount%8!=0) {
                        _memberTotalPage=_memberTotalCount/8+1;
                    }
                    else if (_memberTotalCount%8==0)
                    {
                        _memberTotalPage=_memberTotalCount/8;
                    }
                    NSMutableArray *mMembersArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    // NSLog(@"mMembersArray===%@",mMembersArray);
                    if ( mMembersArray.count>0) {
                        for (int i=0; i< mMembersArray.count; i++) {
                            
                            [memberCodeArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"UserCode"]];
                            [memberNameArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"UserName"]];
                            [memberAddressArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Address"]];
                            [memberPhoneArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Phone"]];
                            [memberGradeArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Grade"]];
                            [memberIntegralArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Integral"]];
                            [memberIntegralAmountArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"IntegralAmount"]];
                            [memberSexArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Sex"]];
                        }
                    }
                    
                    [_searchMemberTableView reloadData];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    //                    if (timer!=nil) {
                    //                        [timer invalidate];
                    //                        timer=nil;
                    //                    }
                    //                    UIViewController *controller=[[GlobalViewController alloc]init];
                    //                    [self.navigationController pushViewController:controller animated:YES];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                        // [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}


-(void)initOrderList
{
    _searchTextField.text=@"";
    orderNumArray=[NSMutableArray array];
    orderTotalNumberArray=[NSMutableArray array];
    orderStatusArray=[NSMutableArray array];
    orderStatus1Array=[NSMutableArray array];
    orderDocTypeArray=[NSMutableArray array];
    orderWeightArray=[NSMutableArray array];
    orderShipmentStatusArray=[NSMutableArray array];
    productNameArray=[NSMutableArray array];
    guideNameArray=[NSMutableArray array];
    memberNameListArray=[NSMutableArray array];
    priceArray=[NSMutableArray array];
    dateArray=[NSMutableArray array];
    
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    if (orderDetailVC.view!=nil) {
        
        [orderDetailVC removeFromParentViewController];
        [orderDetailVC.view removeFromSuperview];
        
    }
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }



    
}

-(void)selectGuideBtnClick
{
    
    if (isOpened) {
        _guideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
          
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=1;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=NO;
        }];
        
    }
    else
    {
        [self requestGuideList];
        _guideListViewContainer.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
          
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=657;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=YES;
        }];
        
    }
    
}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                //  NSLog(@"guideeeee==%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [cashierGuideCodeArray removeAllObjects];
                    [cashierGuideNameArray removeAllObjects];
                    NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [cashierGuideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [cashierGuideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_guideListTableView reloadData];
                   // [_addGuideListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                        // [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (_refreshHeaderView == nil) {
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _depositListTabelView.bounds.size.height, self.view.frame.size.width, _depositListTabelView.bounds.size.height)];
        view.delegate = self;
        [_depositListTabelView addSubview:view];
        _refreshHeaderView = view;
        
        
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderDocTypeArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_depositListTabelView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView==_depositListTabelView) {
        
        [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView==_depositListTabelView) {
        [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }
    
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView==_searchMemberTableView) {
        return memberCodeArray.count;
    }
    
    else if (tableView==_depositListTabelView) {
        return orderNumArray.count;
    }
    else if(tableView==_guideListTableView )
    {
        return cashierGuideCodeArray.count;
    }
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_depositListTabelView) {
        return 120;
    }
    else if(tableView==_guideListTableView )
        return 60;
   
    else if (tableView==_searchMemberTableView)
        return 90;
   
        return 50;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_depositListTabelView) {
        static NSString * const  OrderManagementIdentifier = @"OrderManagementIdentifier";
        DepositTableViewCell *cell=( DepositTableViewCell *)[tableView dequeueReusableCellWithIdentifier: OrderManagementIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"DepositTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
            cell.delegate=self;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
        //        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
      
        cell.buShouYinButton.tag=indexPath.row;
        
        
        if (orderNumArray.count>0) {
            cell.numLabel.text=[orderNumArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.numLabel];
            [Global resizeForLable:cell.numLabel WithText:cell.numLabel.text parentView:self.view];

            CGRect frame=cell.statusLabel.frame;
            frame.origin.x=cell.numLabel.frame.origin.x+cell.numLabel.frame.size.width-5;
            cell.statusLabel.frame=frame;
        }
        
        //  NSLog(@"memberContacts11111==%@",memberContacts);
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.guideNameLabel];
            [Global resizeForLable:cell.guideNameLabel WithText:cell.guideNameLabel.text parentView:self.view];
            CGRect frame=cell.memberNameTagLabel.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
            cell.memberNameTagLabel.frame=frame;
            
            
            
        }
        NSString *memberNameStr=@"";
        if (memberNameListArray.count>0) {
            memberNameStr=[NSString stringWithFormat:@"%@",[memberNameListArray objectAtIndex:indexPath.row]];
            if (memberNameStr.length>0) {
                cell.memberNameLabel.text=memberNameStr;
                // [cell.huiYuanBuDengButton setTitle:@"会员变更" forState:UIControlStateNormal];
            }
            else
            {
                cell.memberNameLabel.text=@"未填写";
                // [cell.huiYuanBuDengButton setTitle:@"会员补登" forState:UIControlStateNormal];
            }
            [Global resizeForLable:cell.memberNameLabel WithText:cell.memberNameLabel.text parentView:self.view];
          //  [self resizeLabel:cell.memberNameLabel];
            CGRect frame1=cell.memberNameLabel.frame;
            frame1.origin.x=cell.memberNameTagLabel.frame.origin.x+cell.memberNameTagLabel.frame.size.width+2;
            cell.memberNameLabel.frame=frame1;
            
            CGRect frame2=cell.dateTagLabel.frame;
            frame2.origin.x=cell.memberNameLabel.frame.origin.x+cell.memberNameLabel.frame.size.width+15;
            cell.dateTagLabel.frame=frame2;
            
            CGRect frame3=cell.dateLabel.frame;
            frame3.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
            cell.dateLabel.frame=frame3;
        }
        
        NSString *statusStr=@"";
        if (orderStatusArray.count>0) {
            statusStr=[orderStatusArray objectAtIndex:indexPath.row];
            cell.statusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
            if ([statusStr isEqualToString:@"未收银"]) {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                [cell.buShouYinButton setUserInteractionEnabled:YES];
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                
            }
            else if ([statusStr isEqualToString:@"已取消"])
            {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.buShouYinButton setUserInteractionEnabled:NO];
                
               
            }
            else if ([statusStr isEqualToString:@"已结算"])
            {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.buShouYinButton setUserInteractionEnabled:NO];
                
                }
            
         //   [self resizeLabel:cell.statusLabel];
             [Global resizeForLable:cell.statusLabel WithText:cell.statusLabel.text parentView:self.view];
        }
        
        
        if (dateArray.count>0) {
            cell.dateLabel.text=[dateArray objectAtIndex:indexPath.row];
        }
        if (orderDocTypeArray.count>0) {
            NSString *docTypeStr=[orderDocTypeArray objectAtIndex:indexPath.row];
            cell.docTypeLabel.text=[NSString stringWithFormat:@"【%@】",docTypeStr];
            
            if ([[orderDocTypeArray objectAtIndex:indexPath.row]isEqualToString:@"未使用"]) {
                [cell.docTypeLabel setTextColor:[Global parseStatusColor:docTypeStr]];
                
            }
            else if ([[orderDocTypeArray objectAtIndex:indexPath.row]isEqualToString:@"已使用"]) {
                [cell.docTypeLabel setTextColor:[Global parseStatusColor:docTypeStr]];
            }
            CGRect frame =cell.docTypeLabel.frame;
            frame.origin.x=cell.statusLabel.frame.origin.x+cell.statusLabel.frame.size.width-3;
            cell.docTypeLabel.frame=frame;
            
        }
        NSString *numberStr=@"";
        NSString *weightStr=@"";
      //  NSString *nameStr=@"";
        if (orderTotalNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%ld",(long)[[orderTotalNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (orderWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%0.02f",[[orderWeightArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (priceArray.count>0) {
            float AvgPrice=[[priceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            cell.depositLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
        }
        if (indexPath.row == [orderNumArray count] - 1)
        {
            if (_PageIndex<=_TotalPage) {
                //  NSLog(@"###LOADING???");
                [self loadOrderNextPage:_PageIndex];
            }
        }
        return cell;
    }
    else if (tableView==_guideListTableView)
    {
        static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
        //        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (cashierGuideNameArray.count>0) {
            cell.guideNameLabel.text=[cashierGuideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    
         else  if (tableView==_searchMemberTableView) {
        
        
        static NSString * const  MemberListIdentifier = @"MemberListCellIdentifier";
        SearchMemberTableViewCell *cell=( SearchMemberTableViewCell *)[tableView dequeueReusableCellWithIdentifier: MemberListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"SearchMemberTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
        //        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (memberSexArray.count>0) {
            if ([[memberSexArray objectAtIndex:indexPath.row] isEqualToString:@"男"]) {
                [cell.sexImageView setImage:[UIImage imageNamed:@"nan_.png"]];
            }
            else
                [cell.sexImageView setImage:[UIImage imageNamed:@"nv_.png"]];
        }
        
        if (memberGradeArray.count>0) {
            cell.gradeLabel.text=[memberGradeArray objectAtIndex:indexPath.row];
           // [self resizeLabel:cell.gradeLabel];
            [Global resizeForLable:cell.gradeLabel WithText:cell.gradeLabel.text parentView:self.view];
        }
        
        if (memberPhoneArray.count>0&&memberNameArray.count>0) {
            NSString *phoneStr=[memberPhoneArray objectAtIndex:indexPath.row];
            NSString *nameStr=[memberNameArray objectAtIndex:indexPath.row];
            NSString *str1=@"(";
            NSString *str2=@")";
            cell.nameAndPhoneLabel.text=[NSString stringWithFormat:@"%@%@%@%@",nameStr,str1,phoneStr,str2];
          //  [self resizeLabel:cell.nameAndPhoneLabel];
             [Global resizeForLable:cell.nameAndPhoneLabel WithText:cell.nameAndPhoneLabel.text parentView:self.view];
            
            //            NSLog(@"phoneStr====%@",phoneStr);
            //            NSLog(@"nameStr====%@",nameStr);
            //            NSLog(@" cell.nameAndPhoneLabel.text====%@", cell.nameAndPhoneLabel.text);
            
            CGRect frame=cell.sexImageView.frame;
            frame.origin.x=cell.nameAndPhoneLabel.frame.origin.x+cell.nameAndPhoneLabel.frame.size.width;
            cell.sexImageView.frame=frame;
            
            CGRect frame1=cell.gradeTagLabel.frame;
            frame1.origin.x=cell.sexImageView.frame.origin.x+cell.sexImageView.frame.size.width+11;
            cell.gradeTagLabel.frame=frame1;
            
            CGRect frame2=cell.gradeLabel.frame;
            frame2.origin.x=cell.gradeTagLabel.frame.origin.x+cell.gradeTagLabel.frame.size.width+2;
            cell.gradeLabel.frame=frame2;
            
            CGRect frame3=cell.integralTagLabel.frame;
            frame3.origin.x=cell.gradeLabel.frame.origin.x+cell.gradeLabel.frame.size.width+11;
            cell.integralTagLabel.frame=frame3;
            
            CGRect frame4=cell.integralLabel.frame;
            frame4.origin.x=cell.integralTagLabel.frame.origin.x+cell.integralTagLabel.frame.size.width+2;
            cell.integralLabel.frame=frame4;
        }
        if (memberAddressArray.count>0) {
            NSString *addressStr1=[memberAddressArray objectAtIndex:indexPath.row];
            if (addressStr1.length>0) {
                cell.addressLabel.text=addressStr1;
            }
            else
            {
                cell.addressLabel.text=@"未填写";
            }
        }
        if (memberIntegralArray.count>0) {
            cell.integralLabel.text=[NSString stringWithFormat:@"%ld",(long)[[memberIntegralArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (indexPath.row == [memberCodeArray count] - 1)
        {
            if (_memberPageIndex<=_memberTotalPage) {
                //  NSLog(@"###LOADING???");
                [self loadMemberNextPage:_memberPageIndex];
            }
        }
        return cell;
    }
    
    return nil;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView==_guideListTableView) {
        guideCodeStr=[cashierGuideCodeArray objectAtIndex:indexPath.row];
        
        _guideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=1;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=NO;
        }];
        _guideNameLabel.text=[cashierGuideNameArray objectAtIndex:indexPath.row];
        //[self resizeLabel1:_guideNameLabel];
        [Global resizeForLable:_guideNameLabel WithText:_guideNameLabel.text parentView:self.view];
        CGRect frameK=_guideNameLabel.frame;
        frameK.origin.x=_guideListArrowImage.frame.origin.x-frameK.size.width-5;
        _guideNameLabel.frame=frameK;

    }
    else if (tableView==_depositListTabelView)
    {
        orderListCellTag=indexPath.row;
        // _reloading =NO;
//        for (UIView *v in _detailPictureView.subviews) {
//            
//            [v removeFromSuperview];
//            
//        }
//
//        [self requestDepositDetail:[orderNumArray objectAtIndex:indexPath.row]];
        if (depositDetailVC.view!=nil) {
            
            [depositDetailVC removeFromParentViewController];
            [depositDetailVC.view removeFromSuperview];
            
        }
        depositDetailVC=[[DepositDetailViewController alloc] init];
        depositDetailVC.delegate=self;
        depositDetailVC.docNumStr=[orderNumArray objectAtIndex:indexPath.row];
        
        
        depositDetailVC.view.frame = CGRectMake(0,
                                                0,
                                                self.view.bounds.size.width,
                                                self.view.bounds.size.height);
        
        [self addChildViewController:depositDetailVC];
        [self.view addSubview:depositDetailVC.view];

        
    }
    else if (tableView==_searchMemberTableView)
    {
        // NSLog(@"buShouYinOrBuDengStr====%@",buShouYinOrBuDengStr);
      
            CGRect frame0=_searchMemberViewContainer.frame;
            frame0.origin.y=768;
            [_searchMemberViewContainer setFrame:frame0];
            _memberInfoNoteLabel.hidden=YES;
            NSString *nameStr=[memberNameArray objectAtIndex:indexPath.row];
            NSString *phoneStr=[memberPhoneArray objectAtIndex:indexPath.row];
            memberCodeStr=[memberCodeArray objectAtIndex:indexPath.row];
            _memberAndPhoneLabel.text=[NSString stringWithFormat:@"%@(%@)",nameStr,phoneStr];
          //  [self resizeLabel:_memberAndPhoneLabel];
            [Global resizeForLable:_memberAndPhoneLabel WithText:_memberAndPhoneLabel.text parentView:self.view];
          
            
            if ([memberGradeArray objectAtIndex:indexPath.row]!= [NSNull null])
            {
                NSString *gradeStr=[memberGradeArray objectAtIndex:indexPath.row];
                _memberGradeLabel.text=gradeStr;
                _memberGradeTagLabel.hidden=NO;
                _memberGradeLabel.hidden=NO;
             //   [self resizeLabel:_memberGradeLabel];
                 [Global resizeForLable:_memberGradeLabel WithText:_memberGradeLabel.text parentView:self.view];
                //_memberGradeLabel.text=[severDataDict.dataDict objectForKey:@"Grade"];
            }//}
            CGRect frame=_memberSexImage.frame;
            frame.origin.x=_memberAndPhoneLabel.frame.origin.x+_memberAndPhoneLabel.frame.size.width+2;
            _memberSexImage.frame=frame;
            CGRect frame1=_memberGradeTagLabel.frame;
            frame1.origin.x=_memberSexImage.frame.origin.x+_memberSexImage.frame.size.width+12;
            _memberGradeTagLabel.frame=frame1;
            CGRect frame2=_memberGradeLabel.frame;
            frame2.origin.x=_memberGradeTagLabel.frame.origin.x+_memberGradeTagLabel.frame.size.width+2;
            _memberGradeLabel.frame=frame2;
            if ([memberSexArray objectAtIndex:indexPath.row]!= [NSNull null] )
            {
                NSString *sexStr1=[memberSexArray objectAtIndex:indexPath.row];
                _memberSexImage.hidden=NO;
                if ([sexStr1 isEqualToString:@"男"]) {
                    [_memberSexImage setImage:[UIImage imageNamed:@"nan_.png"]];
                }
                else
                {
                    [_memberSexImage setImage:[UIImage imageNamed:@"nv_.png"]];
                }
            }
        }
        
    
       
}
//DepositDetailDelegate
-(void)DepositDetailAlphaViewClick
{
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    
}
-(void)DepositDetailCanCelDepositClick
{
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    cancelOrderVC=[[CancelOrderOrDepositViewController alloc] init];
    cancelOrderVC.delegate=self;
    cancelOrderVC.DocNumStr=depositDetailVC.detailNumLabel.text;
    cancelOrderVC.DocTypeStr=@"Deposit";
    cancelOrderVC.titleStr=@"取消定金单";
    
//    cancelOrderVC.statusStr1=depositDetailVC.detailStatusLabel.text;
//    cancelOrderVC.statusStr2=depositDetailVC.detailTypeLabel.text;
    
        
    cancelOrderVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOrderVC];
    [self.view addSubview:cancelOrderVC.view];
    
}
-(void)DepositDetailRelateOrderClick
{

    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
    orderDetailVC=[[OrderDetailViewController alloc] init];
    orderDetailVC.delegate=self;
    orderDetailVC.docNumStr=depositDetailVC.relateOrderNumLabel.text;
    orderDetailVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:orderDetailVC];
    [self.view addSubview:orderDetailVC.view];
    
    
    
    
}

-(void)submitTheSelectedMember
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:memberCodeStr forKey:@"MemberCode"];
        [params setObject:orderStr forKey:@"DocNum"];
        [params setObject:@"DOrder" forKey:@"DocType"];
        
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"Guide/AddMemberTobills" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            //  NSLog(@"severdata======%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    CGRect frame1=_searchMemberViewContainer.frame;
                    frame1.origin.y=768;
                    [_searchMemberViewContainer setFrame:frame1];
                    
                    
                    [orderNumArray removeAllObjects];
                    [orderTotalNumberArray removeAllObjects];
                    [orderStatusArray removeAllObjects];
                    [orderStatus1Array removeAllObjects];
                    [orderDocTypeArray removeAllObjects];
                    [orderWeightArray removeAllObjects];
                    [orderShipmentStatusArray removeAllObjects];
                    [productNameArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                    [memberNameListArray removeAllObjects];
                    [priceArray removeAllObjects];
                    [dateArray removeAllObjects];
                    
                    
                    _PageIndex=0;
                    [self loadOrderNextPage:_PageIndex];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                        //   [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

- (void)textClick
{
    [_searchMemberTextField becomeFirstResponder];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
     if (textField==_addDepositSearchMemberTextField) {
       
        [self performSelector:@selector(textClick) withObject:nil afterDelay:0.1];
       
        [memberCodeArray removeAllObjects];
        [memberNameArray removeAllObjects];
        [memberPhoneArray removeAllObjects];
        [memberGradeArray removeAllObjects];
        [memberAddressArray removeAllObjects];
        [memberIntegralArray removeAllObjects];
        [memberIntegralAmountArray removeAllObjects];
        [memberSexArray removeAllObjects];
        [_searchMemberTableView reloadData];
        _totalMemberLabel.text=[NSString stringWithFormat:@"共有0个结果"];
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_searchMemberViewContainer.frame;
            viewFrame.origin.y=0;
            _searchMemberViewContainer.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
        return NO;
        
    }
    
      return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField==_depositAmountTextField)
    {
        _totalAmountLabel.text=[Global floatConvertPercentile:[_depositAmountTextField.text floatValue]];
    }
  
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField==_searchMemberTextField) {
        [_searchMemberTextField resignFirstResponder];
        [memberCodeArray removeAllObjects];
        [memberNameArray removeAllObjects];
        [memberPhoneArray removeAllObjects];
        [memberGradeArray removeAllObjects];
        [memberAddressArray removeAllObjects];
        [memberIntegralArray removeAllObjects];
        [memberIntegralAmountArray removeAllObjects ];
        [memberSexArray removeAllObjects];
        
        _memberPageIndex=0;
        [self loadMemberNextPage:_memberPageIndex];
        
        
        // return NO;
    }
       if (textField==_searchTextField) {
        [orderNumArray removeAllObjects];
        [orderTotalNumberArray removeAllObjects];
        [orderStatusArray removeAllObjects];
        [orderWeightArray removeAllObjects];
        [orderShipmentStatusArray removeAllObjects];
        [orderDocTypeArray removeAllObjects];
        [productNameArray removeAllObjects];
        [guideNameArray removeAllObjects];
        [memberNameListArray removeAllObjects];
        [priceArray removeAllObjects];
        [dateArray removeAllObjects];
        
        _PageIndex=0;
        [self loadOrderNextPage:_PageIndex];
        [_searchTextField resignFirstResponder];
    }
    
    
    return YES;
}
- (void)textViewDidChange:(UITextView *)textView
{
      if (textView==_addDepositRemarkView) {
        if (textView.text.length == 0) {
            _addDepositRemarkViewImage.hidden=NO;
            _addDepositRemarkViewLabel.hidden=NO;
        }
        else
        {
            _addDepositRemarkViewImage.hidden=YES;
            _addDepositRemarkViewLabel.hidden=YES;
            
        }
   }

}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
     if (textView==_addDepositRemarkView) {
        if (_remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height+352>768) {
            
            
            [UIView animateWithDuration:0.1 animations:^{
                CGRect viewFrame=_addDepositScrollView.frame;
                viewFrame.origin.y=-(_remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height+250-768);
                _addDepositScrollView.frame=viewFrame;
            } completion:^(BOOL finished){
                
            }];
        }
        
    }

    
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
      if (textView==_addDepositRemarkView) {
        [_addDepositScrollView setContentOffset:CGPointMake(0, 0)];
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_addDepositScrollView.frame;
            viewFrame.origin.y=0;
            _addDepositScrollView.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
        
    }

       
}

-(void)addMemberBtnClick
{
    if (addMemberVC.view!=nil) {
        
        [addMemberVC removeFromParentViewController];
        [addMemberVC.view removeFromSuperview];
        
    }
    addMemberVC=[[AddMemberViewController alloc] init];
    addMemberVC.delegate=self;
    addMemberVC.addOrEditStr=@"A";
    addMemberVC.userCodeStr=@"";
    addMemberVC.docNumStr=@"";
    addMemberVC.view.frame = CGRectMake(0,
                                        0,
                                        self.view.bounds.size.width,
                                        self.view.bounds.size.height);
    
    [self addChildViewController:addMemberVC];
    [self.view addSubview:addMemberVC.view];
    
    
}
-(void)addOrEditMemberSuccess:(NSString *)memberCodeString memberGradeString:(NSString *)memberGradeString memberNameString:(NSString *)memberNameString memberPhoneString:(NSString *)memberPhoneString memberSexString:(NSString *)memberSexString memberIntegralString:(NSString *)memberIntegralString
{
    _memberInfoNoteLabel.hidden=YES;
   
    memberCodeStr=memberCodeString;
    //  NSString *integralStr=[memberIntegralArray objectAtIndex:indexPath.row];
    _memberAndPhoneLabel.text=[NSString stringWithFormat:@"%@(%@)",memberNameString,memberPhoneString];
    
    // [self resizeLabel:_memberAndPhoneLabel];
    [Global resizeForLable:_memberAndPhoneLabel WithText:_memberAndPhoneLabel.text parentView:self.view];
    integralAvailabalStr=@"";
    // _integralAvailabelLabel.text=[NSString stringWithFormat:@"可用金额  ¥ 0.00"];
    
    
        _memberGradeLabel.text=memberGradeString;
        _memberGradeTagLabel.hidden=NO;
        _memberGradeLabel.hidden=NO;
        //  [self resizeLabel:_memberGradeLabel];
        [Global resizeForLable:_memberGradeLabel WithText:_memberGradeLabel.text parentView:self.view];
        //_memberGradeLabel.text=[severDataDict.dataDict objectForKey:@"Grade"];
    
    CGRect frame=_memberSexImage.frame;
    frame.origin.x=_memberAndPhoneLabel.frame.origin.x+_memberAndPhoneLabel.frame.size.width+2;
    _memberSexImage.frame=frame;
    
    CGRect frame1=_memberGradeTagLabel.frame;
    frame1.origin.x=_memberSexImage.frame.origin.x+_memberSexImage.frame.size.width+12;
    _memberGradeTagLabel.frame=frame1;
    
    CGRect frame2=_memberGradeLabel.frame;
    frame2.origin.x=_memberGradeTagLabel.frame.origin.x+_memberGradeTagLabel.frame.size.width+2;
    _memberGradeLabel.frame=frame2;
    
        _memberSexImage.hidden=NO;
        if ([memberSexString isEqualToString:@"男"]) {
            [_memberSexImage setImage:[UIImage imageNamed:@"nan_.png"]];
        }
        else if ([memberSexString isEqualToString:@"女"])
        {
            [_memberSexImage setImage:[UIImage imageNamed:@"nv_.png"]];
        }
    

}

-(IBAction)saveDepositBtnClick:(id)sender
{
   
    [upYunImageArray removeAllObjects];
    if (_pictureView.subviews.count>2) {
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            [params setObject:@"DDemand" forKey:@"uploadType"];
            //   NSLog(@"params====%@",params);
            [HttpRequest requestLoginData:@"System/GetFormParams" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                //  NSLog(@"serrr111==%@",severDataDict.dataDict);
                // [_cashierSearchMemberTextField resignFirstResponder];
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        [Global setUpYunUrl:[severDataDict.dataDict objectForKey:@"action"]];
                        // signatureStr=[severDataDict.dataDict objectForKey:@"signature"];
                        // policyStr=[severDataDict.dataDict objectForKey:@"policy"];
                        
                        [Global setSignatureStr:[severDataDict.dataDict objectForKey:@"signature"]];
                        [Global setPolicyStr:[severDataDict.dataDict objectForKey:@"policy"]];
                        
                        [self upToUpYun];
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                            [Global loginViewController:self noteStr:requestResultStr];
                            //   [Global loginViewController:self];
                        }
                        
                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
        }
        
        
        //    [self upToUpYun];
    }
    else
    {
        // NSLog(@"14444477777");
        [self saveDepositToServer];
    }
}
-(void)upToUpYun
{
    __block NSInteger count=0;
    UpYun *uy = [[UpYun alloc] init];
    uy.successBlocker = ^(id data)
    {
        count++;
        // NSLog(@"count======%d",count );
        // NSLog(@"_pictureView.subviews.count======%d",_pictureView.subviews.count );
        
        NSString *imageURL;
        NSString *imageWIDTH;
        NSString *imageHEIGHT;
        imageURL=[data objectForKey:@"url"];
        imageWIDTH=[data objectForKey:@"image-width"];
        imageHEIGHT=[data objectForKey:@"image-height"];
        NSMutableDictionary *upYunImageDict=[NSMutableDictionary dictionary];
        [upYunImageDict setObject:imageURL forKey:@"ImageUrl"];
        [upYunImageDict setObject:imageWIDTH forKey:@"ImageWidth"];
        [upYunImageDict setObject:imageHEIGHT forKey:@"ImageHeigh"];
        [upYunImageArray addObject:upYunImageDict];
        if (count==_pictureView.subviews.count-2-(_pictureView.subviews.count-2)/2) {
            
            [Global hideProgressHUDInternal:self.view];
            [self saveDepositToServer];
        }
        
        
    };
    uy.failBlocker = ^(NSError * error)
    {
        [Global hideProgressHUDInternal:self.view];
        //NSString *message = [error.userInfo objectForKey:@"message"];
        
        [Global showTextHudSub:@"上传失败" view:self.view];
//        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"error" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
//        [alert show];
        //  NSLog(@"%@",error);
    };
    uy.progressBlocker = ^(CGFloat percent, long long requestDidSendBytes)
    {
        // [_pv setProgress:0.3333333333+percent/3];
    };
    
    if (_memberAndPhoneLabel.text.length>0&&[_depositAmountTextField.text floatValue]>0) {
        
        [Global showIndeterminateHudSub:@"正上传UPYUN，请稍后。。。" delay:120 view:self.view];
        if (upYunImageArray.count==0) {
            
            for (UIView *v in _pictureView.subviews) {
                if (v.tag!=90&&v.tag>50) {
                    UIImageView *imageview=(UIImageView *)v;
                    UIImage *sampleImg=[self imageCompress:imageview.image];
                    
                    //            NSData *imageData = UIImageJPEGRepresentation(imageview.image,0.01);
                    //            //NSLog(@"imageData===%@",imageData);
                    //            UIImage *newImage = [UIImage imageWithData:imageData];
                    
                    uy.bucket=@"";
                    [uy uploadFile:sampleImg saveKey:[self getSaveKey]];
                }
                
            }
        }
        
        
    }
    else
    {
        if (_memberAndPhoneLabel.text.length==0)
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择会员" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        
        
        else if ([_depositAmountTextField.text floatValue]==0)
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请输入定金金额" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        
    }
    
}
-(void)saveDepositToServer
{
   
    if (_memberAndPhoneLabel.text.length>0&&[_depositAmountTextField.text floatValue]>0) {
        
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            
            [params setObject:upYunImageArray forKey:@"DataLine"];
            [params setObject:_addDepositRemarkView.text forKey:@"Remark"];
            [params setObject:guideCodeStr forKey:@"GuideCode"];
            [params setObject:_minAmountTextField.text forKey:@"MinAmount"];
            [params setObject:_maxAmountTextField.text forKey:@"MaxAmount"];
            [params setObject:memberCodeStr forKey:@"MemberCode"];
            [params setObject:_depositAmountTextField.text forKey:@"Subscription"];
            [params setObject:_chengseListBtn.titleLabel.text forKey:@"ProductName1"];
            [params setObject:_zhushiListBtn.titleLabel.text forKey:@"ProductName2"];
            [params setObject:_shipinListBtn.titleLabel.text forKey:@"ThrtypeCode"];
            
            //  NSLog(@"addddPARAM1111===%@",params);
            [HttpRequest requestData:@"Guide/EditDeposit" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
//                        [orderNumArray removeAllObjects];
//                        [orderTotalNumberArray removeAllObjects];
//                        [orderStatusArray removeAllObjects];
//                        [orderStatus1Array removeAllObjects];
//                        [orderDocTypeArray removeAllObjects];
//                        [orderWeightArray removeAllObjects];
//                        [orderShipmentStatusArray removeAllObjects];
//                        [productNameArray removeAllObjects];
//                        [guideNameArray removeAllObjects];
//                        [memberNameListArray removeAllObjects];
//                        [priceArray removeAllObjects];
//                        [dateArray removeAllObjects];
//                        
//                        
//                        _PageIndex=0;
//                        [self loadOrderNextPage:_PageIndex];
                        _minAmountTextField.text=@"";
                        _maxAmountTextField.text=@"";
                        _guideNameLabel.text=@"";
                        _depositAmountTextField.text=@"";
                        guideCodeStr=@"";
                      //  [UIView animateWithDuration:0.1 animations:^{
                            CGRect viewFrameA=_addDepositView.frame;
                            viewFrameA.origin.y=768;
                            _addDepositView.frame=viewFrameA;
//                        } completion:^(BOOL finished){
//                            
//                        }];
                        _isLoad=@"N";
                        [_addDepositScrollView setContentOffset:CGPointMake(0, 0)];
                        CGRect viewFrame=_pictureView.frame;
                        viewFrame.size.height=118;
                        _pictureView.frame=viewFrame;
                        
                        CGRect viewFrame0=_pictureViewLineLabel.frame;
                        viewFrame0.origin.y= _pictureView.frame.size.height-1;
                        _pictureViewLineLabel.frame=viewFrame0;
                        
                        CGRect viewFrame1=_remarkViewContainer.frame;
                        viewFrame1.origin.y=_pictureView.frame.origin.y+_pictureView.frame.size.height+15;
                        _remarkViewContainer.frame=viewFrame1;
                        
                        [_addDepositScrollView setContentSize:CGSizeMake(0, _remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height)];

                        
//                        _textViewImageView.hidden=NO;
//                        _textViewLabel.hidden=NO;
                        _addDepositRemarkView.text=@"";
                        for (UIView *v in _pictureView.subviews) {
                            if (v.tag!=90) {
                                
                                [v removeFromSuperview];
                            }
                            
                        }
                       
                        
                        CGRect viewFrame11=_addPictureButton.frame;
                        viewFrame11.origin.y=10;
                        viewFrame11.origin.x=16;
                        _addPictureButton.frame=viewFrame11;
                        
                        if (cashierVC.view!=nil) {
                            
                            [cashierVC removeFromParentViewController];
                            [cashierVC.view removeFromSuperview];
                            
                        }
                        cashierVC=[[CashierViewController alloc] init];
                        cashierVC.delegate=self;
                        cashierVC.docTypeStr=@"Deposit";
                        cashierVC.docNumStr=[severDataDict.dataDict objectForKey:@"DocNum"];
                        cashierVC.view.frame = CGRectMake(0,
                                                          0,
                                                          self.view.bounds.size.width,
                                                          self.view.bounds.size.height);
                        
                        [self addChildViewController:cashierVC];
                        [self.view addSubview:cashierVC.view];

                        
                        
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                            [Global loginViewController:self noteStr:requestResultStr];
                            //    [Global loginViewController:self];
                        }
                        
                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
            
        }
    }
    else
    {
        // NSLog(<#NSString *format, ...#>)
        if (_memberAndPhoneLabel.text.length==0)
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择会员" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        
        
        else if ([_depositAmountTextField.text floatValue]==0)
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请输入定金金额" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        
    }
    
}

-(void)imgBtnCLick:(UIButton *)sender
{
    imageBtnTag=sender.tag;
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_photoPickerViewContainer.frame;
         viewFrame.origin.y=0;
         _photoPickerViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
         
     }];
    
}

#pragma 拍照选择照片协议方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    
   // NSData *data;
    
    if ([mediaType isEqualToString:@"public.image"]){
        
        //切忌不可直接使用originImage，因为这是没有经过格式化的图片数据，可能会导致选择的图片颠倒或是失真等现象的发生，从UIImagePickerControllerOriginalImage中的Origin可以看出，很原始，哈哈
        UIImage *originImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        // NSLog(@"originImage.",originImage.size);
        //图片压缩，因为原图都是很大的，不必要传原图
        // UIImage *scaleImage = [self scaleImage:originImage toScale:1.0];
        //  UIImage *sampleImg=[self imageCompress:originImage];
        
        //以下这两步都是比较耗时的操作，最好开一个HUD提示用户，这样体验会好些，不至于阻塞界面
        //       if (UIImagePNGRepresentation(scaleImage) == nil) {
        //将图片转换为JPG格式的二进制数据
        //   data = UIImageJPEGRepresentation(scaleImage, 1.0);
        //        }
        //        else {
        ////          //  将图片转换为PNG格式的二进制数据
        //           data = UIImagePNGRepresentation(scaleImage);
        //       }
        
        
        
        //将二进制数据生成UIImage
        // UIImage *image = [UIImage imageWithData:data];
        
        // NSData *imageData = UIImageJPEGRepresentation(image,0.01);
        //NSLog(@"imageData===%@",imageData);
        // UIImage *newImage = [UIImage imageWithData:imageData];
        
        //将图片传递给截取界面进行截取并设置回调方法（协议）
        CaptureViewController *captureView = [[CaptureViewController alloc] init];
        captureView.delegate = self;
        captureView.image = originImage;
        //隐藏UIImagePickerController本身的导航栏
        picker.navigationBar.hidden = NO;
        [picker pushViewController:captureView animated:YES];
        
    }
}

#pragma mark - 图片回传协议方法
-(void)passImage:(UIImage *)image
{
    
    UIImage *sampleImg=image;
    //NSLog(@"sampleImg===%f,%f",sampleImg.size.width,sampleImg.size.height);
    // isLoad=NO;
    
    CGRect frame=_addPictureButton.frame;
    
    UIImageView *getImageView=(UIImageView *)[_pictureView viewWithTag:imageBtnTag+100];
    if (getImageView==nil) {
        
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame=frame;
        btn.tag=5*btn.frame.origin.y/100+btn.frame.origin.x/117;
        [btn addTarget:self action:@selector(imgBtnCLick:) forControlEvents:UIControlEventTouchUpInside];
        
        UIImageView *sampleImageView=[[UIImageView alloc] initWithFrame:frame];
        sampleImageView.tag=5*sampleImageView.frame.origin.y/100+sampleImageView.frame.origin.x/117+100;
        //  sampleImageView.tag=9;
        [sampleImageView setImage:sampleImg];
        [_pictureView addSubview:sampleImageView];
        [_pictureView addSubview:btn];
        // [selectePictureArray addObject:sampleImageView];
        // NSLog(@"btn.tag===%d",btn.tag);
        //NSLog(@"sampleImageView.tag===%d",sampleImageView.tag);
        
        CGRect frame1=_addPictureButton.frame;
        frame1.origin.x=_addPictureButton.frame.origin.x+_addPictureButton.frame.size.width+27;
        _addPictureButton.frame=frame1;
        if (frame1.origin.x>484) {
            frame1.origin.x=16;
            frame1.origin.y=115;
            _addPictureButton.frame=frame1;
            
            CGRect viewFrame=_pictureView.frame;
            viewFrame.size.height=223;
            _pictureView.frame=viewFrame;
            
        }
        if (frame1.origin.x>484&&frame1.origin.y==115) {
            _addPictureButton.hidden=YES;
        }
        CGRect viewFrame0=_pictureViewLineLabel.frame;
        viewFrame0.origin.y= _pictureView.frame.size.height-1;
        _pictureViewLineLabel.frame=viewFrame0;
        CGRect viewFrame1=_remarkViewContainer.frame;
        viewFrame1.origin.y=_pictureView.frame.origin.y+_pictureView.frame.size.height+15;
        _remarkViewContainer.frame=viewFrame1;
        
//        CGRect viewFrame2=_saveBtn.frame;
//        viewFrame2.origin.y=_remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height+20;
//        _saveBtn.frame=viewFrame2;
        
        [_addDepositScrollView setContentSize:CGSizeMake(0, _remarkViewContainer.frame.origin.y+ _remarkViewContainer.frame.size.height+10)];
        [_addDepositScrollView setScrollEnabled:YES];
    }
    else
    {
        getImageView.image=sampleImg;
    }
    imageBtnTag=10000;
    
}

#pragma mark- 缩放图片
-(UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
    UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}

-(IBAction)albumOrCameraBtnClick:(UIButton *)sender
{
    _isLoad=@"Y";
    CGRect viewFrame=_photoPickerViewContainer.frame;
    viewFrame.origin.y=768;
    _photoPickerViewContainer.frame=viewFrame;
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    switch (sender.tag) {
        case 20000://Take picture
            
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                
            }else{
                NSLog(@"模拟器无法打开相机");
            }
            [self presentViewController:picker animated:YES completion:nil];
            break;
            
        case 20001://From album
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentViewController:picker animated:YES completion:nil];
            break;
            
        default:
            
            break;
    }
    
}

-(IBAction)cancelBtnClick:(id)sender
{
    // _CameraHelper.selectOrCancel=@"CANCEL";
    CGRect viewFrame=_photoPickerViewContainer.frame;
    viewFrame.origin.y=768;
    _photoPickerViewContainer.frame=viewFrame;
    // [_CameraHelper stopRunning];
    
    
}

-(NSString * )getSaveKey {
    NSDate *d = [NSDate date];
    int value = arc4random() % 1000;
    return [NSString stringWithFormat:@"/%d/%d/%d.jpg",[self getYear:d],[self getMonth:d],value];
}

- (int)getYear:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSYearCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int year=[comps year];
    return year;
}

- (int)getMonth:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSMonthCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int month = [comps month];
    return month;
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    
    [self dismissViewControllerAnimated:NO completion:^{
        
        CGRect viewFrame=_addDepositView.frame;
        viewFrame.origin.y=0;
        _addDepositView.frame=viewFrame;
    }];
    
}
-(UIImage *)imageCompress:(UIImage *)image
{
    UIImage *comImage=image;
    NSData * sendImageData = UIImageJPEGRepresentation(comImage, 1.0);
    NSUInteger sizeOrigin = [sendImageData length];
    NSUInteger sizeOriginKB = sizeOrigin / 1024;
    
    if (sizeOriginKB >100) {
        float a = 100.0000;
        float b = (float)sizeOriginKB;
        float q = sqrtf(a / b);
        
        CGSize sizeImage = [comImage size];
        CGFloat widthSmall = sizeImage.width * q;
        CGFloat heighSmall = sizeImage.height * q;
        CGSize sizeImageSmall = CGSizeMake(widthSmall, heighSmall);
        
        UIGraphicsBeginImageContext(sizeImageSmall);
        CGRect smallImageRect = CGRectMake(0, 0, sizeImageSmall.width, sizeImageSmall.height);
        [image drawInRect:smallImageRect];
        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        NSData *dataImage = UIImageJPEGRepresentation(smallImage, 1.0);
        sendImageData = dataImage;
        
        comImage= smallImage;
        // [_imageview1.image retain];
    }
    return comImage;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
